<!-- menu表单弹窗 -->
<form id="form-menu" lay-filter="form-menu" class="layui-form model-form">
    <input name="id" type="hidden"/>
    <input name="parentId" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input name="name" placeholder="请输入" type="text" class="layui-input" maxlength="255" lay-verify="required" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">路径</label>
        <div class="layui-input-block">
            <input name="url" placeholder="请输入" type="text" class="layui-input" maxlength="200"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图标</label>
        <div class="layui-input-block">
            <input name="icon" placeholder="请输入" type="text" class="layui-input" maxlength="200"/>
        </div>
    </div>

    <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="form-menu-submit" type="button" lay-submit>保存</button>
    </div>

</form>

<script>
    layui.use(['layer', 'form', 'admin','http','tools'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var admin = layui.admin;
        var http = layui.http;
        var tools = layui.tools;
        var device = layui.device();

        var viewId = "#form-menu";
        var view = $(viewId);

        var rowData = admin.getTempData('rowData');
        form.val('form-menu', rowData);

        // 表单提交事件
        form.on('submit(form-menu-submit)', function (data) {
            http.post('menu/save', data.field, function (res) {
                layer.closeAll('loading');
                if (res.ok) {
                    //修改
                    if(rowData.id && tools.refs){  //更新
                        tools.refs.update(res.data);
                        tools.table.reload("view-menuTreeTable");
                    }else if(tools.refs){  //新增子项
                    tools.renderTable();
                }else{ //新增根
                    tools.renderTable();
                }
                    http.okMsg(res.msg);
                    admin.closeDialog('#form-menu');
                } else {
                    http.fail(data);
                }
            });
            return false;
        });
    });
</script>